package org.jeecg.modules.workflow;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.Base64;

public class Test {


    public static String getAccessToken(String corpId, String corpSecret) {
        String tokenUrl = "https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid=wwbfc297bb323a06e3&corpsecret=" + corpSecret;
        try {
            URL url = new URL(tokenUrl);
            HttpURLConnection connection = (HttpURLConnection) url.openConnection();
            connection.setRequestMethod("GET");
            connection.connect();

            BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
            String inputLine;
            StringBuilder response = new StringBuilder();

            while ((inputLine = in.readLine()) != null) {
                response.append(inputLine);
            }
            in.close();

            return response.toString();
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }



    }
    public static void main(String[] args) {
        String encodedUrl = "305f0201020458305602010502041419e3a30201000204354c880902046792017b042433623739643462652d363733362d346430612d383464322d6464306438316631353435620204030800010203026990040436303030020227110201000400";

        try {
            byte[] decodedBytes = Base64.getDecoder().decode(encodedUrl);
            // 假设URL从偏移量12开始
            int offset = 12;
            int urlLength = (decodedBytes[offset] & 0xFF) << 24 |
                    (decodedBytes[offset + 1] & 0xFF) << 16 |
                    (decodedBytes[offset + 2] & 0xFF) << 8 |
                    (decodedBytes[offset + 3] & 0xFF);

            byte[] urlBytes = new byte[urlLength];
            System.arraycopy(decodedBytes, offset + 4, urlBytes, 0, urlLength);
            String url = new String(urlBytes);
            System.out.println("解析后的URL: " + url);
        } catch (Exception e) {
            System.out.println("解析失败，可能是加密数据或编码格式错误");
            e.printStackTrace();
        }
    }

    public static byte[] hexStringToByteArray(String s) {
        int len = s.length();
        byte[] data = new byte[len / 2];
        for (int i = 0; i < len; i += 2) {
            data[i / 2] = (byte) ((Character.digit(s.charAt(i), 16) << 4)
                    + Character.digit(s.charAt(i + 1), 16));
        }
        return data;
    }

}
